<template>
	<view class="goods-box">
		<view class="style_1" :style="{backgroundColor:box_bg}" v-if="styleType==1" @click="goodsClick()">
			<view class="image">
				<image :src="$img_path('/course/uni.png')" mode="aspectFill"></image>
			</view>
			<view class="info">
				<view class="name more-row" :style="{'--row-num':2}">
					线上课程标题线上课程标题线上课程标题
				</view>
				<view class="center-text">
					<slot name="center"></slot>
				</view>
				<view class="price_num" :style="{justifyContent: jc==1 ? 'space-between':'flex-start'}">
					<view class="price"><text>￥</text>10.00</view>
					<slot name="np">
						<view class="n_price">
							￥10.00
						</view>
					</slot>
				</view>
				
			</view>
		</view>
		
		<view class="style_2" :style="{backgroundColor:box_bg}" v-if="styleType==2" @click="goodsClick()">
			<view :style="{width:imageStyle.width,height:imageStyle.height}" class="image">
				<image :src="$img_path('/course/uni.png')" mode="aspectFill"></image>
				<view class="tag">
					标签
				</view>
			</view>
			<view class="info" :style="{'--img-width':img_width}">
				<view class="name more-row" :style="{'--row-num':2}">
					线上课程标题线上课程标题线上课程标题
				</view>
				<view class="center-text">
					<slot name="center"></slot>
				</view>
				<view class="price_num">
					<slot name="priceBox">
						<view class="left" :style="{justifyContent: jc==1 ? 'space-between':'flex-start'}">
							<view class="price"><text>￥</text>10.00</view>
							<slot name="np">
								<view class="n_price">
									￥10.00
								</view>
							</slot>
						</view>
					</slot>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:'goods',
		props:{
			styleType:{
				type:Number,
				default:1
			},
			jc:{
				type:String,
				default:'2'
			},
			imageStyle:{
				type:Object,
				default:()=>{
					return {
						width:'166rpx',
						height:'166rpx'
					}
				}
			},
			box_bg:{
				type:String,
				default:'#FFFFFF'
			}
		},
		data(){
			return {
				img_width:''
			}
		},
		watch:{
			imageStyle(val){
				this.Topx()
			}
		},
		mounted() {
			this.Topx()
		},
		methods:{
			Topx(){
				if(this.styleType==1){
					return
				}
				let i = this.imageStyle.width.indexOf('rpx')
				let n = this.imageStyle.width.slice(0,i)
				this.img_width = uni.upx2px(n)+'px'
			},
			
			goodsClick(){
				// uni.navigateTo({
				// 	url:'/pagesCourse/classify/detail'
				// })
				this.$emit('goodsClick')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goods-box{
		width: 100%;
		// margin-bottom: 24rpx;
		.style_1{
			width: 100%;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			overflow: hidden;
			&>.image{
				width: 100%;
				height: 246rpx;
				image{
					width: 100%;
					height: 100%;
					border-radius: 20rpx;
				}
			}
			.info{
				padding: 16rpx 16rpx 20rpx;
				box-sizing: border-box;
				.name{
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;
					line-height: 44rpx;
				}
				.center-text{
					font-weight: bold;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					margin-top: 6rpx;
				}
				.price_num{
					display: flex;
					flex-wrap: wrap;
					align-items: flex-end;
					justify-content: space-between;
					.price{
						font-weight: 800;
						font-size: 40rpx;
						color: #FF2E2E;
						// line-height: 40rpx;
						text{
							font-size: 32rpx;
						}
					}
					.num{
						font-weight: 400;
						font-size: 26rpx;
						color: #333333;
						line-height: 40rpx;
						margin-top: 6rpx;
					}
				}
				.n_price{
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-decoration: line-through;
					// margin-top: 6rpx;
					margin-left: 2rpx;
				}
			}
		}
	
		.style_2{
			width: 100%;
			display: flex;
			// align-items: center;
			padding: 26rpx 18rpx 28rpx 20rpx;
			box-sizing: border-box;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			&>.image{
				width: 166rpx;
				height: 166rpx;
				image{
					width: 100%;
					height: 100%;
					border-radius: 20rpx;
				}
				position: relative;
				.tag{
					position: absolute;
					right: 10rpx;
					bottom: 10rpx;
					width: 94rpx;
					height: 50rpx;
					background: rgba(0,0,0,0.4);
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 50rpx;
					text-align: center;
				}
			}
			.info{
				width: calc(100% - var(--img-width));
				padding-left: 24rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.name{
					font-weight: bold;
					font-size: 30rpx;
					color: #333333;
					line-height: 42rpx;
				}
				.center-text{
					font-weight: bold;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
				}
				.price_num{
					display: flex;
					align-items: flex-end;
					justify-content: space-between;
					margin-top: 26rpx;
					.left{
						display: flex;
						align-items: flex-end;
						.price{
							font-weight: 900;
							font-size: 40rpx;
							color: #FF2E2E;
							line-height: 40rpx;
							text{
								font-size: 32rpx;
							}
						}
						.n_price{
							font-weight: 400;
							font-size: 24rpx;
							color: #999999;
							line-height: 34rpx;
							text-decoration: line-through;
							margin-top: 6rpx;
							margin-left: 18rpx;
						}
					}
					
					.num{
						font-weight: 400;
						font-size: 20rpx;
						color: #333333;
						line-height: 40rpx;
						margin-top: 6rpx;
					}
				}
			}
		}
	}
</style>